package com.sfzy.controller;

import com.github.pagehelper.PageInfo;
import com.sfzy.entity.Psych;
import com.sfzy.service.PsychService;
import com.sfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName PsychController
 * @Description TODO
 * @Author niejiacan
 * @Date 2025年08月13日 21:32
 * @Version 1.0
 */
@RestController
@RequestMapping("psych")
public class PsychController {
    @Autowired
    private PsychService psychService;

    @PostMapping
    public R addPsych(@RequestBody Psych psych){
        int i = psychService.addPsych(psych);
        if(i==0){
            return R.fail();
        }
        return R.ok();
    }

    @PutMapping
    public R updatePsych(@RequestBody Psych psych){
        int i = psychService.updatePsych(psych);
        if (i==0){
            R.fail();
        }
        return R.ok();
    }

    @DeleteMapping("{id}")
    public R deletePsych(@PathVariable("id") int id){
        int i = psychService.deletePsych(id);
        if(i==0){
            return R.fail();
        }
        return  R.ok();
    }

    @GetMapping("{id}")
    public R selectPsych(@PathVariable("id") int id){
        Psych psych = psychService.selectPsych(id);
        return R.ok(psych);
    }

    @GetMapping("pageTitle")
    public R pageTitle(Psych psych,
                       @RequestParam(required = false,defaultValue = "1") int pageNum,
                       @RequestParam(required = false,defaultValue = "5") int pageSize){
        PageInfo<Psych> psychPageInfo = psychService.pageTitle(psych, pageNum, pageSize);
        return R.ok(psychPageInfo);
    }




}
